{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Event Detection from Time Series Data\n",
    " \n",
    "Description: sensors data is somehow processed to generate a sequence of **events**, which is then mined for\n",
    "interesting episodesspecified pattern to increase the computational efficiency of the mining process."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [],
   "source": [
    "from nptdms import TdmsFile\n",
    "from sklearn import preprocessing \n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "#from sklearn.decomposition import PCA\n",
    "from sklearn.cluster import KMeans\n",
    "from collections import defaultdict\n",
    "#from sklearn.preprocessing import StandardScaler\n",
    "import matplotlib.pyplot as plt\n",
    "import seglearn as sgl\n",
    "from matplotlib.mlab import PCA\n",
    "import math\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Untitled']"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# load in data\n",
    "tdms_file = TdmsFile(\".\\\\FW-1-1\\\\new material\\\\AKF_SS-FW2-H04521-H05000.tdms\")\n",
    "#list out the groups\n",
    "groups = tdms_file.groups() \n",
    "df = tdms_file.object('Untitled').as_dataframe()\n",
    "df.columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "s_fr = df['Stempel_1 (Formula Result)']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 89,
   "metadata": {},
   "outputs": [],
   "source": [
    "def Trend_Change(line,delta): \n",
    "    delta_new = abs(np.diff(line))\n",
    "    max_d = np.max(delta_new)\n",
    "    print(max_d)\n",
    "    if max_d > delta:\n",
    "        delta = delta_new\n",
    "        k = np.where(delta_new > max_d/2)[0][0]+1\n",
    "        return k\n",
    "    else: return -1\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 92,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "190.79344000000037\n",
      "1600.58124\n",
      "2744.073720000044\n",
      "647.766799999983\n",
      "3836.482880000025\n",
      "3672.087520000001\n",
      "866.4706000000006\n",
      "254.58820000000014\n",
      "254.58820000000014\n",
      "254.58820000000014\n",
      "254.58820000000014\n",
      "254.58820000000014\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAY0AAAD8CAYAAACLrvgBAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4xLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvAOZPmwAAIABJREFUeJzt3XmcXGWZ6PHfU1Xd1Z3e94R0IFsnJGHJ0oQgm4YtBDQ4LoN3RqLixEGc0fF+PgrjzIB6veqdGWEYBURZRQ0IOqCTkImgsoYskj0k6QRCmqT3Jb13V9V7/zhvJdWd6u5Kb6eW5/v51KdPPec9531yUt1PvWcVYwxKKaVULDxuJ6CUUipxaNFQSikVMy0aSimlYqZFQymlVMy0aCillIqZFg2llFIx06KhlFIqZlo0lFJKxUyLhlJKqZj53E5grBUXF5vp06e7nYZSSiWUbdu2NRhjSoZrl3RFY/r06WzdutXtNJRSKqGIyJFY2unuKaWUUjHToqGUUipmWjSUUkrFTIuGUkqpmGnRUEopFTMtGkoppWKmRUMppVTMtGgoFUXNoYPsfPEFQqGg26koFVeS7uI+pUZr9x82suHB/wCg7t13uPrW21zOSKn4oSMNpSLU7j3A//z4AYqmzGT+FcvZuXE9jdVH3U5LqbgRU9EQkXwReUZE3haRfSJyiYgUishGETlofxbYtiIi94lIlYjsFJHFEetZbdsfFJHVEfElIrLLLnOfiIiNR+1DqfFS8+yL+Hzn8oEVn+TKT9+Kx+th10svuJ2WUnEj1pHGfwAvGGPOBS4E9gF3AC8aYyqAF+17gOuBCvtaAzwATgEA7gIuBpYCd0UUgQds2/ByK2x8sD6UGnPB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xhBfMzyBRbgDIvvEZHNQBsQ/qPsWr4iciNQZ4zZFhkeYv3xluuQi5xhTmP6OYgh3/uBl40xr4QXOcO8JmTbGmM+C5wF7AP+0u1cIXq+InIW8AlOFbZ+i5xhXhOxbe/EKcQX4exy+rpbuSZl0QgzxrQAfwSuBy60Iw6Ap3COG4BTaacBiHOwOQ9oioxb5Ti7tAaLj2W+K+zw8XJjzFLgZeDgwHxjzKuaU7s0RpvvpcBHRORdnCH4cpxvRfl22w1cv5vb9rRcReTJIdq7uV2HzFdE7gJKcPZzx0O+Q25bY0wQ53csvEvV7d+xaJ/bPcBsoMrGJ4lIVRzkG3XbGmOO211QPThfepcOzDXGnEb/OTiTAyCJ8ML55cq305nAK8CNODfyCh9YvhV41k7fTv+DXk/b6QX0P+h1GOeAl89Oz+DUQa8F45BvqY35gReB5fb9DfQ/8LXZnDrw9Q7OQa8CO11o522xbcMHvlaOwXb+IKcO0v2K/gfCvxgP2zZarhGxd+l/IDwutmuUbft54HUgc0CbuMg3nKtd52wbE+DfgH+Lp8/BYJ8FG488EB4X+Q74HEyJ2Lb3At9z63Mw6v+EeHsBFwBvATuB3cC/2PhHgV32P/SPwEwbz8D5o1eFcyxhZsS6voFzVsR+Is4wwDlj4YCd941xyvdfcYb4+4GvRLQX4Ee2711AZcS8z9l/RxXw2Yh4pV33IeCH2Is6x/ADPdNuuyq7Lf3xsG0HyfXvcb5tBXC+Yf00nrZrlHwDdv3b7etf4ilfThUND/CazWU38HPs2VTx8jkYuG0HxCOLRlzkO+Bz8FLEtn2SU2dcTvjnQK8IV0opFbOkPqahlFJqbGnRUEopFTMtGkoppWKmRUMppVTMtGgopZSKmRYNpZRSMdOioZRSKmZaNJRSSsXs/wPop3GoezB6UQAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x1ad479ea5c0>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "len_s = 50000#len(s_fr)\n",
    "delta =  276\n",
    "win_size = 1000\n",
    "i = 38000\n",
    "j = i;\n",
    "\n",
    "while (i<len_s):\n",
    "    k = Trend_Change(s_fr[j:i+win_size],delta)\n",
    "    if (k != -1):\n",
    "       s_fr[j:j+k].plot()\n",
    "       s_fr[j+k+1:i+win_size].plot()\n",
    "       j = i+win_size \n",
    "    i += win_size\n",
    "   "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "metadata": {},
   "outputs": [
    {
     "ename": "TypeError",
     "evalue": "Empty 'DataFrame': no numeric data to plot",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-72-146788599c81>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[0;32m      2\u001b[0m \u001b[0mdelta\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mnp\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mdiff\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mline\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      3\u001b[0m \u001b[0mk\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mnp\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mwhere\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mdelta\u001b[0m \u001b[1;33m>\u001b[0m \u001b[0mabs\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mnp\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mmax\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mdelta\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m/\u001b[0m\u001b[1;36m2\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m+\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 4\u001b[1;33m \u001b[0mline\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m:\u001b[0m\u001b[0mk\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mplot\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m      5\u001b[0m \u001b[0mline\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mk\u001b[0m\u001b[1;33m+\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;36m41000\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mplot\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mc:\\users\\xiaoli yang\\appdata\\local\\programs\\python\\python35\\lib\\site-packages\\pandas\\plotting\\_core.py\u001b[0m in \u001b[0;36m__call__\u001b[1;34m(self, kind, ax, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, label, secondary_y, **kwds)\u001b[0m\n\u001b[0;32m   2501\u001b[0m                            \u001b[0mcolormap\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mcolormap\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mtable\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mtable\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0myerr\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0myerr\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   2502\u001b[0m                            \u001b[0mxerr\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mxerr\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mlabel\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mlabel\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0msecondary_y\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0msecondary_y\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 2503\u001b[1;33m                            **kwds)\n\u001b[0m\u001b[0;32m   2504\u001b[0m     \u001b[0m__call__\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m__doc__\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mplot_series\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m__doc__\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   2505\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mc:\\users\\xiaoli yang\\appdata\\local\\programs\\python\\python35\\lib\\site-packages\\pandas\\plotting\\_core.py\u001b[0m in \u001b[0;36mplot_series\u001b[1;34m(data, kind, ax, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, label, secondary_y, **kwds)\u001b[0m\n\u001b[0;32m   1925\u001b[0m                  \u001b[0myerr\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0myerr\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mxerr\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mxerr\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   1926\u001b[0m                  \u001b[0mlabel\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mlabel\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0msecondary_y\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0msecondary_y\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 1927\u001b[1;33m                  **kwds)\n\u001b[0m\u001b[0;32m   1928\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   1929\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mc:\\users\\xiaoli yang\\appdata\\local\\programs\\python\\python35\\lib\\site-packages\\pandas\\plotting\\_core.py\u001b[0m in \u001b[0;36m_plot\u001b[1;34m(data, x, y, subplots, ax, kind, **kwds)\u001b[0m\n\u001b[0;32m   1727\u001b[0m         \u001b[0mplot_obj\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mklass\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mdata\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0msubplots\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0msubplots\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0max\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0max\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mkind\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mkind\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m**\u001b[0m\u001b[0mkwds\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   1728\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 1729\u001b[1;33m     \u001b[0mplot_obj\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mgenerate\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m   1730\u001b[0m     \u001b[0mplot_obj\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mdraw\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   1731\u001b[0m     \u001b[1;32mreturn\u001b[0m \u001b[0mplot_obj\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mresult\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mc:\\users\\xiaoli yang\\appdata\\local\\programs\\python\\python35\\lib\\site-packages\\pandas\\plotting\\_core.py\u001b[0m in \u001b[0;36mgenerate\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m    248\u001b[0m     \u001b[1;32mdef\u001b[0m \u001b[0mgenerate\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    249\u001b[0m         \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_args_adjust\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 250\u001b[1;33m         \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_compute_plot_data\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    251\u001b[0m         \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_setup_subplots\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    252\u001b[0m         \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_make_plot\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mc:\\users\\xiaoli yang\\appdata\\local\\programs\\python\\python35\\lib\\site-packages\\pandas\\plotting\\_core.py\u001b[0m in \u001b[0;36m_compute_plot_data\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m    363\u001b[0m         \u001b[1;32mif\u001b[0m \u001b[0mis_empty\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    364\u001b[0m             raise TypeError('Empty {0!r}: no numeric data to '\n\u001b[1;32m--> 365\u001b[1;33m                             'plot'.format(numeric_data.__class__.__name__))\n\u001b[0m\u001b[0;32m    366\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    367\u001b[0m         \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mdata\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mnumeric_data\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mTypeError\u001b[0m: Empty 'DataFrame': no numeric data to plot"
     ]
    }
   ],
   "source": [
    "line = s_fr[40800:41200]\n",
    "delta = np.diff(line)\n",
    "k = np.where(delta > abs(np.max(delta))/2)[0][0]+1\n",
    "line[1:k].plot()\n",
    "line[k+1:41000].plot()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2744.073720000044"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.max(delta)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "def Find_Likelihood_Criteria()：\n",
    "    "
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
